home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / PGM_TOOL / PCKSELFM / SELFMOD.PAS < prev   
Pascal/Delphi Source File  |  1991-01-18  |  2KB  |  63 lines

  1.  
  2. program SelfMod;
  3.  
  4. {
  5.    This demonstrates a technique for creating self-modifying .EXE files. It
  6.    has an advantage over techniques which use typed constants, in that it will
  7.    survive LZEXEC and PkLite(tm).
  8.  
  9.    Note that if the program is run before LZEXEC is used to compress it, the
  10.    compressed program will not have been initialized. This is because LZEXEC
  11.    strips off the config block (and everything else) at the end of the .EXE
  12.    file. This problem does not occur with PKLite(tm).
  13.  
  14.    To run the demo, compile the program and execute it twice. Whatever
  15.    string you enter is written to the end of the .EXE file.
  16.  
  17.    To further demonstrate it's ablities, compress the file with PKLite(tm) or
  18.    LZEXEC after compiling.
  19.  
  20.    Address all questions and comments to:
  21.  
  22.               PCkS Associates
  23.               138 Frances Place
  24.               Hillside, NJ 07205
  25.  
  26.               On CompuServe, EasyPlex to    70152,332
  27.               On Delphi                     CHICKENJN
  28.               On GENie                      J.NICHOLSON1
  29.  
  30.  
  31. }
  32.  
  33.  
  34.  
  35. Uses PCkSelfM;
  36.  
  37. type ConfigBlock = string[40];
  38.  
  39. var
  40.     MyConfig : ConfigBlock;
  41.  
  42. begin
  43. if ConfigBlockPresent(SizeOf(ConfigBlock)) then
  44.     if ReadConfigBlock(MyConfig,SizeOf(ConfigBlock)) then begin
  45.         writeln('Old value of MyConfig: ',MyConfig);
  46.         write('Enter new value: ');
  47.         readln(MyConfig);
  48.         if ConfigBlockRewrite(MyConfig,SizeOf(ConfigBlock)) then
  49.             writeln('Rewrote the block.')
  50.         else writeln('ConfigBlockRewrite failed.');
  51.         end
  52.     else writeln('ReadConfigBlock failed')
  53. else begin
  54.     write('Enter inital value for MyConfig: ');
  55.     readln(MyConfig);
  56.     if NewConfigBlock(MyConfig,SizeOf(ConfigBlock)) then
  57.        writeln('Created new config block')
  58.     else writeln('NewConfigBlock failed.');
  59.     end;
  60. end.
  61.  
  62.  
  63.